package com.mgq.java8.stream;

import java.util.Optional;
import java.util.stream.Stream;

/**
 * <b>功能：</b>Reduce<br>
 * <b>Copyright TCSL</b>
 * <li>版本&nbsp;&nbsp;&nbsp;&nbsp;修改日期&nbsp;&nbsp;&nbsp;&nbsp;部　　门&nbsp;&nbsp;&nbsp;&nbsp;作　者&nbsp;&nbsp;&nbsp;&nbsp;变更内容</li><hr>
 * <li>v1.0&nbsp;&nbsp;&nbsp;&nbsp;20220414&nbsp;&nbsp;营业后台&nbsp;&nbsp;&nbsp;&nbsp;马广奇&nbsp;&nbsp;&nbsp;&nbsp;创建类</li>
 * <br><br>
 *
 * @author 马广奇
 * @version 2022-04-14 20:43
 */
public class Reduce {

    /**
     * reduce求和
     */
    public static void reduce() {
        Stream<Integer> integerStream = Stream.of(1, 2, 3, 4);
        Optional<Integer> sum = integerStream.reduce((a, b) -> (a + b));
        sum.ifPresent(System.out::println);
    }

    public static void main(String[] args) {
        reduce();
    }
}
